package com.itboye.textileexpes.presenter;

import java.util.List;
import java.util.Observer;

import com.itboye.core.interfaces.ICompleteListener;
import com.itboye.textileexpes.beans.AppUpdateBean;
import com.itboye.textileexpes.interfaces.IAppUpdate;
import com.itboye.textileexpes.interfaces.IGetYanZhengMa;
import com.itboye.textileexpes.repository.APPUpdateRepository;
import com.itboye.textileexpres.base.BasePresenter;
import com.itboye.textileexpres.base.ResultEntity;

public class AppUpdatePresenter extends BasePresenter implements
		IAppUpdate<AppUpdateBean> {
	// 获取版本信息
	public static final String version_success = MainPresenter.class.getName()
			+ "_version_success";
	public static final String version_fail = MainPresenter.class.getName()
			+ "_version_fail";

	// 验证码修改密码
	public static final String pass_wold_success = MainPresenter.class
			.getName() + "_pass_wold_success";
	public static final String pass_wold_fail = MainPresenter.class.getName()
			+ "_pass_wold_fail";
	// 验证码修改密码
	public static final String KEfu_success = MainPresenter.class.getName()
			+ "_KEfu_success";
	public static final String KEfu_fail = MainPresenter.class.getName()
			+ "_KEfu_fail";

	public AppUpdatePresenter(Observer observer) {
		super(observer);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void add(AppUpdateBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void delete(AppUpdateBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void update(AppUpdateBean model) {
		// TODO Auto-generated method stub

	}

	@Override
	public void getInfo(AppUpdateBean model) {
		// TODO Auto-generated method stub
		IAppUpdate<AppUpdateBean> addGoods = new APPUpdateRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(version_success);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(version_fail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.getInfo(model);
	}

	@Override
	public List<AppUpdateBean> query(AppUpdateBean model) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void onUpdate(String code, String country, String mobile,
			String password) {
		// TODO Auto-generated method stub
		IAppUpdate<AppUpdateBean> addGoods = new APPUpdateRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(pass_wold_success);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(pass_wold_fail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.onUpdate(code, country, mobile, password);// (model);//(model);
	}

	@Override
	public void onKefu() {
		// TODO Auto-generated method stub
		IAppUpdate<AppUpdateBean> addGoods = new APPUpdateRepository(
				new ICompleteListener() {

					@Override
					public void success(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(KEfu_success);
						setChanged();
						notifyObservers(result);
					}

					@Override
					public void failure(ResultEntity result) {
						// TODO Auto-generated method stub
						result.setEventTag(Tag_Success);
						result.setEventType(KEfu_fail);
						setChanged();
						notifyObservers(result);

					}
				});
		addGoods.onKefu();
	}

}
